# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=olefile
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.44
pkgrel=1
arch=('any')
license=('BSD')
url="https://www.decalage.info/olefile"
depends=()
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
options=('staticlibs')
source=(https://github.com/decalage2/olefile/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('021fbed5c539881d7f1360fb27e942fdfa7c78006bed39e6cd6f3dd9e7bd68da')

prepare() {
  cd ${srcdir}
  cp -r "${_realname}-${pkgver}" "python2-build-${CARCH}"
  cp -r "${_realname}-${pkgver}" "python3-build-${CARCH}"
}

package_python3-olefile() {
  pkgdesc="Python3 library to parse, read and write Microsoft OLE2 files (formerly OleFileIO_PL) (mingw-w64)"
  depends+=("${MINGW_PACKAGE_PREFIX}-python3")

  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})
  local _py3basever=$(${MINGW_PREFIX}/bin/python3 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")
  
  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}/" --optimize=0

  install -Dm644 doc/LICENSE.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
  install -Dm644 README.md doc/* -t "${pkgdir}${MINGW_PREFIX}/share/doc/python3-${_realname}/README"
}

package_python2-olefile() {
  pkgdesc="Python2 library to parse, read and write Microsoft OLE2 files (formerly OleFileIO_PL) (mingw-w64)"
  depends+=("${MINGW_PACKAGE_PREFIX}-python2")

  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})
  local _py2basever=$(${MINGW_PREFIX}/bin/python2 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}/" --optimize=0

  install -Dm644 doc/LICENSE.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
  install -Dm644 README.md doc/* -t "${pkgdir}${MINGW_PREFIX}/share/doc/python2-${_realname}/README"
}

package_mingw-w64-i686-python2-olefile() {
  package_python2-olefile
}

package_mingw-w64-i686-python3-olefile() {
  package_python3-olefile
}

package_mingw-w64-x86_64-python2-olefile() {
  package_python2-olefile
}

package_mingw-w64-x86_64-python3-olefile() {
  package_python3-olefile
}
